"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = __importDefault(require("express"));
const https_1 = __importDefault(require("https"));
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const config = __importStar(require("../config"));
const privateKey = fs_1.default.readFileSync(path_1.default.join(__dirname, "../", "./ssl/feifan.key"), "utf8");
const certificate = fs_1.default.readFileSync(path_1.default.join(__dirname, "../", "./ssl/feifan.pem"), "utf8");
const credentials = {
    key: privateKey,
    cert: certificate,
};
const app = (0, express_1.default)();
//cookie
const cookie_parser_1 = __importDefault(require("cookie-parser"));
app.use((0, cookie_parser_1.default)(config.key));
//token验证中间件
const token_1 = __importDefault(require("../cookie/token"));
app.use(token_1.default);
//图片防盗链中间件
const theft_1 = require("../theft/theft");
app.use(theft_1.untheft);
app.use(express_1.default.static("public"));
app.use(express_1.default.urlencoded({ extended: true }));
app.use(express_1.default.json());
//日志中间件
const log_1 = __importDefault(require("../log"));
app.use(log_1.default);
//文章
const article_1 = __importDefault(require("./article"));
app.use("/api/article", article_1.default);
const articlecomment_1 = __importDefault(require("./articlecomment"));
app.use("/api/articlecomment", articlecomment_1.default);
const top_1 = __importDefault(require("./top"));
app.use("/api/article", top_1.default);
//user表
const user_1 = __importDefault(require("./user"));
app.use("/api/user", user_1.default);
//评论中间件
const commemt_1 = __importDefault(require("./commemt"));
app.use("/api/comment", commemt_1.default);
//错误处理中间件
const errhandle_1 = __importDefault(require("./middleware/errhandle"));
app.use(errhandle_1.default);
if (config.isHttps) {
    const httpsServer = https_1.default.createServer(credentials, app);
    httpsServer.listen(443, () => {
        console.log(`HTTPS Server is running on: https://localhost:${443}`);
    });
}
else {
    app.listen(config.httpPort, () => {
        console.log(`端口${config.httpPort}已开启服务`);
    });
}
